package com.tender.exceptionhandler;

import com.tender.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import com.tender.exceptions.ShiroException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    // @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public Result<String> handleAllExceptions(Exception ex) {
        Result<String> result = Result.ofErrorMessage("系统异常");
        log.error(" ============= 全局异常处理器，具体异常：", ex);
        if (ex instanceof ShiroException) {
            ShiroException shiroException = (ShiroException) ex;
            result.setResultMsg(shiroException.getMessage());
            result.setResultCode(shiroException.getCode());
        }
        // TODO

        return result;
    }

}
